package top.suven.http.oauth.token;

import top.suven.base.http.JsonParse;
import top.suven.http.oauth.vo.OAuthParameter;
import org.apache.oltu.oauth2.as.request.OAuthAuthzRequest;
import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
import org.apache.oltu.oauth2.common.message.types.ResponseType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @ClassName: AuthorizeController.java
 * @Description: OAUTH2.0的认证服务, auth 请求验证
 * @Author suven.wang
 * @Date 2018/7/26 18:01
 * @Copyright: (c) 2018 gc by https://www.gc.com.cn/
 * @Version : 1.0.0
 *  --------------------------------------------------------
 *  modifyer    modifyTime                 comment
 *
 *  --------------------------------------------------------
 */
public class OAuthAuthxRequest extends OAuthAuthzRequest {

    private Logger logger = LoggerFactory.getLogger(OAuthAuthxRequest.class);

    protected boolean enforceClientAuthentication = false;

    public OAuthAuthxRequest(HttpServletRequest request) throws OAuthSystemException, OAuthProblemException {

        super(request);
    }


    /*
    * 判断响应的类型是否为CODE
    * */
    public boolean isCode() {
        return ResponseType.CODE.name().equalsIgnoreCase(this.getResponseType());
    }

    /*
    * 判断响应的类型是否为TOKEN
    * */
    public boolean isToken() {
        return ResponseType.TOKEN.name().equalsIgnoreCase(this.getResponseType());
    }

    /*
    * 获取 request 对象
    * */
    public HttpServletRequest request() {
        return this.request;
    }

    public OAuthParameter getOAuthParameter() throws Exception{
        Map map = this.request.getParameterMap();
        OAuthParameter auth = JsonParse.parseFrom(map,OAuthParameter.class);
        return auth;
    }


}
